package com.google.code.drift.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.google.code.drift.R;
import com.google.code.drift.api.AppSkyApp;

public class QuitRoomDialog extends AlertDialog.Builder {

	AppSkyApp app = null;
	
	public QuitRoomDialog(final Context context) {
		super(context);
		app = (AppSkyApp) ((Activity) context).getApplication();
		setDialogView(context);
	}
	
	private void setDialogView(final Context context) {
		if (app.getMyInfo().isRoomOwner() && app.getMyInfo().getRoomPersons().size() > 0) {
			setIcon(R.drawable.ic_dialog_alert);
			setTitle(R.string.can_not_quit_room);
			setPositiveButton(R.string.ok,
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
						}
					});
		} else {
			setIcon(R.drawable.ic_interrogative);
			setTitle(R.string.sure_quit_room);
			setPositiveButton(R.string.ok,
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
							((Activity) context).finish();
						}
					});
			setNegativeButton(R.string.cancel,
					new DialogInterface.OnClickListener() {
						@Override
						public void onClick(DialogInterface dialog, int which) {
						}
					});
		}
	}
}
